package com.singfan.common.nosql.mongo;

import com.mongodb.MongoClient;
import com.singfan.common.SingFanException;
import com.singfan.common.db.DbLogger;
import com.singfan.common.db.provider.C3p0ConnectionPoolProvider;
import com.singfan.common.db.provider.ConnectionPoolProvider;
import com.singfan.common.db.provider.DbConfigProvider;
import com.singfan.common.db.provider.XmlDbConfigProvider;
import com.singfan.common.nosql.mongo.provider.MongoClientProvider;
import com.singfan.common.nosql.mongo.provider.MongoConfigProvider;
import com.singfan.common.nosql.mongo.provider.SimpleMongoClientProvider;
import com.singfan.common.nosql.mongo.provider.SimpleMongoConfigProvider;

/**
 * MongoDB框架上下文
 * Author: hansonghe
 * Date: 2015-08-21 09:49
 * Desc:
 */
public class MongoContext {
    private static MongoConfigProvider mongoConfigProvider;
    private static MongoClientProvider mongoClientProvider;

    /**
     * 初始化SingFan数据库环境
     */
    public static void init(){
        try {
            mongoConfigProvider = new SimpleMongoConfigProvider();
            mongoConfigProvider.init();

            mongoClientProvider = new SimpleMongoClientProvider();
            mongoClientProvider.init();
        }
        catch (Exception ex){
            throw new SingFanException(String.format("MongoContext.init() error: %s", ex.getMessage()), ex);
        }
    }

    /**
     * 获取MongoDB配置信息提供类
     * @return MongoDB配置信息提供类
     */
    public static MongoConfigProvider getMongoConfigProvider() {
        return mongoConfigProvider;
    }

    public static MongoClientProvider getMongoClientProvider(){
        return mongoClientProvider;
    }
}
